package com.sfx.concurrent.demo.concurrent.TestWaitNotify;

import lombok.extern.slf4j.Slf4j;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-12-29
 * Time: 20:56
 */

@Slf4j(topic = "c.demo1")
public class TestWaitNotify {
    private static final Object obj = new Object();
    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            synchronized (obj) {
                log.debug("执行...");
                try {
                    obj.wait(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("其他代码");
            }
        },"t1").start();
        Thread.sleep(500);
        System.out.println("唤醒obj中的线程");
        synchronized (obj) {
            obj.notifyAll();//唤醒在waitSet中的所有线程
        }
    }
}